package ch6;

import java.util.Scanner;

public class OrderManager {

	public static void main(String[] args) {
		System.out.println("吃货联盟订餐系统");
		// 保存菜品信息，菜名，单价，点赞数
		String prodname[] = { "红烧带鱼", "肉末茄子", "果蔬" };
		double prices[] = { 76, 28, 10 };
		int[] praise = new int[3];

		String[] ordername = new String[6];
		ordername[0] = "王小明";
		ordername[1] = "王大祥";

		String[] dishMsg = new String[6];
		dishMsg[0] = prodname[0];
		dishMsg[1] = prodname[1];

		int ordernum[] = new int[6];
		ordernum[0] = 1;
		ordernum[1] = 2;
		int[] times = new int[6]; // 保存送餐时间
		times[0] = 11;
		times[1] = 12;

		String[] addresses = new String[6]; // 保存送餐地址
		addresses[0] = "工大";
		addresses[1] = "蜂巢园";

		int[] states = new int[6]; // 保存订单状态： 0：已预订 1：已完成
		states[0] = 0;
		states[1] = 1;

		double[] sumPrices = new double[6]; // 保存订单的总金额
		sumPrices[0] = 76;
		sumPrices[1] = 56;

		Scanner in = new Scanner(System.in);
		// .....
		int choice = 0;
		while (true) {
			System.out.println("1: 2: 3: 4: 5 ,6 :0:exit");
			choice = in.nextInt();
			switch (choice) {
			case 1: {
				// 显示餐品，给顾客挑选
				for (int i = 0; i < prodname.length; i++) {
					System.out.println((i + 1) + "  " + prodname[i] + " " + prices[i] + "  " + praise[i]);
				}
				// 顾客开始选择
				int ch = 0;
				while (true) {
					ch = in.nextInt();
					if (ch >= 1 && ch <= 3)
						break;
				}
				System.out.println("客户姓名：");
				String xingming = in.next();
				System.out.println("要几份？");
				int fenshu = in.nextInt();
				System.out.println("送餐时间:");
				int shijian = in.nextInt();

				System.out.println("地址：");
				String adr = in.next();
				// 要餐袋中找一个空位置，放这个新订单
				for (int i = 0; i < ordername.length; i++) {
					if (ordername[i] == null) {
						ordername[i] = xingming;
						dishMsg[i] = prodname[ch - 1];
						ordernum[i] = fenshu;
						times[i] = shijian;
						addresses[i] = adr;
						double money = prices[ch - 1] * fenshu;
						money = money >= 50 ? money : money + 5;
						sumPrices[i] = money;
						break;
					}
				}
			}
				break;
			case 2: {

				System.out.println("餐袋信息：");
				System.out.println("序号  姓名     餐品信息 \t数量\t 送餐时间 \t 地址\t 金额  状态");

				for (int i = 0; i < ordername.length; i++) {
					if (ordername[i] == null)
						break;
					System.out.println((i + 1) + ordername[i] + "\t" + dishMsg[i] + "\t" + ordernum[i] + "\t" + times[i]
							+ "\t" + addresses[i] + "\t" + sumPrices[i] + "\t" + (states[i] == 1 ? "已完成" : "已预订"));
				}

			}
				break;
			}

			if (choice == 0)
				break;
		}
	}

}
